/*
 *   @Author: 1296
 *   @Date: 2025-03-20
 *   @Description: 入口文件
*/

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from "@/store"
import i18n from './i18n'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
// 如果需要复用插件，解开下面的注释以及plugins文件夹下的注释
// import axios from 'axios'
// import LoadingPlugin from '@/plugins/loading'

import DefaultLayout from './layouts/DefaultLayout.vue'
import LoginRegisterLayout from './layouts/LoginRegisterLayout.vue'
import EmptyLayout from "./layouts/EmptyLayout.vue"
import AfterLoginLayout from "./layouts/LoggedInLayout.vue"
import RedirectLayout from "@/layouts/RedirectLayout.vue"
import FloatingButtons from './components/FloatingButtons.vue';

const app = createApp(App)
const resizeObserverErrHandler = (err) => {
    if (err.message.includes('ResizeObserver')) return;
    console.error(err);
};

window.addEventListener('error', resizeObserverErrHandler);
// 注册布局组件
app.component('DefaultLayout', DefaultLayout)
app.component('LoginRegisterLayout', LoginRegisterLayout)
app.component('EmptyLayout', EmptyLayout)
app.component('AfterLoginLayout', AfterLoginLayout)
app.component('RedirectLayout', RedirectLayout)
app.component('FloatingButtons', FloatingButtons);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}

// 使用插件
app.use(i18n)
app.use(router)
app.use(store)
app.use(ElementPlus)
// 安装加载插件（如果需要）
// app.use(LoadingPlugin, {
//     axios,
//     router,
//     color: '#1890ff',
//     minShowTime: 300,
//     delay: 200
// })

router.beforeEach((to) => {
    if (!i18n?.global) {
        console.error('i18n实例未初始化！')
        document.title = 'Quick-Sign'
        return
    }
    const t = i18n.global.t
    const titleKey = to.meta.title || 'quickSign'
    document.title = `${t(titleKey)} | ${t('appName')}`
})

app.mount('#app')
